#!/bin/bash

set -e
set -x

# wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
bypy download node_exporter-1.8.2.linux-amd64.tar.gz
tar xf node_exporter-1.8.2.linux-amd64.tar.gz
mv node_exporter-1.8.2.linux-amd64 /opt/node_exporter
chown -R prometheus:prometheus /opt/node_exporter/
cp node_exporter.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable node_exporter --now
sh ../check_port.sh 9100
time=$(date +'%Y_%m_%d_%H_%M_%S')
sed -i.$time '$r node_exporter.tpl' /opt/prometheus/prometheus.yml
curl -X POST http://localhost:9090/-/reload

set +x
set +e